import { defineConfig } from 'vite'

import vue from '@vitejs/plugin-vue'

import Components from 'unplugin-vue-components/vite'

import { VantResolver } from 'unplugin-vue-components/resolvers'

import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  skipLibCheck: true,
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()]
    })
  ],
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: (content, loaderContext) => {
          if (loaderContext.endsWith('assets/scss/comm.scss') || loaderContext.endsWith('assets/scss/flex.scss')) {
            return content
          }
          return `@import "./src/assets/scss/comm.scss";@import "./src/assets/scss/flex.scss";${content}`
        }
      }
    }
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, '.', 'src')
    }
  },
  server: {
    host: '0.0.0.0',
    port: 80,
    proxy: {
      '/api': {
        target: `/`,
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '')
      }
    }
  },
  build: {
    outDir: 'huan'
  }
})
